package com.example.service.impl;

import com.example.dao.EvaluateUserBehaviorMapper;
import com.example.dao.TransactMapper;
import com.example.microinvestcommon.vo.UserOrderVo;
import com.example.service.CancelTradeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class CancelTradeServiceImpl implements CancelTradeService {

    private final EvaluateUserBehaviorMapper evaluateUserBehaviorMapper;
    private final TransactMapper transactMapper;
    CancelTradeServiceImpl(EvaluateUserBehaviorMapper evaluateUserBehaviorMapper,TransactMapper transactMapper){
        this.evaluateUserBehaviorMapper=evaluateUserBehaviorMapper;
        this.transactMapper=transactMapper;
    }

    //回滚购买订单服务
    @Override
    @Transactional
    public void transactBuyTreadService(UserOrderVo userOrderVo) {
        //返还用户金额
        evaluateUserBehaviorMapper.addUserBalance(userOrderVo.getUserId(),userOrderVo.getOrderAllAmount());

    }

    //回滚卖出订单服务
    @Override
    @Transactional
    public void transactSellTreadService(UserOrderVo userOrderVo) {
        //返还股票数量
     transactMapper.addStockQuantity(userOrderVo.getUserId(),userOrderVo.getStockSymbol(),userOrderVo.getStockQuantity());

    }
}
